#!/bin/sh
# PCP QA Test No. 799
# checkout pmlogrewrite -q
#
# non-valgrind dual of qa/1476
#
# Copyright (c) 2019 Ken McDonell.  All Rights Reserved.
#
# check-group-exclude: pmdumplog
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

export PCP_DERIVED_CONFIG=

# real QA test starts here
echo "log mandatory on once {" >$tmp.config
pminfo \
| sed \
    -e 's/\..*//' \
| sort \
| uniq >>$tmp.config
echo "}" >>$tmp.config

cat $tmp.config >>$seq_full

pmlogger -l $tmp.log -c $tmp.config -s 1 $tmp
cat $tmp.log >>$seq_full

echo "values in the archive ..." >>$seq_full
textgrep=""
[ $PCP_PLATFORM = linux ] && textgrep="-a"
pmdumplog $tmp \
| grep $textgrep ' value ' \
| wc -l >>$seq_full
pminfo -d -a $tmp sample.load >>$seq_full 2>&1
if pminfo -d -a $tmp sample.load >/dev/null 2>&1
then
    :
else
    echo "Arrgh sample.load not in test archive ..."
    pmdumplog $tmp
    _exit 1
fi

echo "=== no change ==="
pmlogrewrite -c $PCP_VAR_DIR/config/pmlogrewrite -Dappl0,appl3 -q -i $tmp 2>&1
pmlogcheck -w $tmp

echo
echo "=== one type change ==="
cat <<'End-of-File' >$tmp.config
metric sample.load {
    sem -> discrete
}
End-of-File
pminfo -d -a $tmp sample.load
pmlogrewrite -c $tmp.config -v -q -i $tmp 2>&1
pmlogcheck -w $tmp
pminfo -d -a $tmp sample.load

# success, all done
status=0
exit
